<?php
include "config.php";

$username=$_POST['username'];
$pswd=$_POST['pswd'];

$sql="select * from user where username='{$username}' and password='{$pswd}'";

$rst=$mysqli->query($sql);
$row=$rst->fetch_assoc();

if($row){
    // 登录成功
    setcookie('username',$username,time()+3600,'/');
    setcookie('userid',$row['id'],time()+3600,'/');
    echo "<script>location='index.php'</script>";
}else{
    // 账号或密码错误,登录失败
    echo "<script>location='login.php'</script>";
}

 ?>